package com.qf.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author sunyamei
 * @version V1.0
 * @Project springmvc_Demo
 * @Package com.qf.interceptor
 * @Description:
 * @Date 2022/7/14 15:33
 */
public class MyInterceptor  implements HandlerInterceptor {

    /**
     * 指定处理器之前执行
     * @param request
     * @param response
     * @param handler
     * @return    如果方法返回值 true 则放行  如果返回false 则拦截后面的均不执行
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle");
        return true;//默认false 拦截
    }

    /**
     * 执行处理器方法之后执行（执行返回值之前执行）
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle");
    }

    /**
     * 执行处理器方法完全执行完之后（执行返回值之后执行）
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion");
    }

}
